package com.dj.shop.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.dj.shop.util.QingStorUtil;
import com.dj.shop.vo.Result;
import org.springframework.util.StringUtils;
import com.qingstor.sdk.exception.QSException;
import com.qingstor.sdk.service.Bucket;
import com.qingstor.sdk.service.QingStor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.util.Objects;

/**
 * @author: create by yyj
 * @version: v1.0
 * @description: com.dj.shop.controller
 * @date:2019/3/9
 */
@RestController
@RequestMapping("/web/qingstor")
public class BucketController {

    private final Logger logger = LoggerFactory.getLogger(ManuController.class);
    /**
     *
     * @description
     *      上传文件
     * @date: 2019/3/10 16:59
     * @author: yyj
     * @UpdateUser:
     * @UpdateRemark:
     * @param objectKey
     * objectKey:需要上传到的服务器路径，格式为 文件夹名+文件名，如：folder/aaa.jpg,根路径直接写文件名
     * @param filePath
     * filePath：文件所在的本地路径
     * @return
     */
    @RequestMapping("/fileUpload")
    public Result putObject(String objectKey, String filePath){
        Bucket bucket = QingStorUtil.CreatBucket();
        return QingStorUtil.putObject(bucket,objectKey,filePath);

    }

    /**
     *
     * @description
     *      获取文件访问RUL
     * @date: 2019/3/10 17:10
     * @author: yyj
     * @UpdateUser:
     * @UpdateRemark:
     * @param FileName
     * FileName:文件所在的服务器路径，如：folder/aaa.jpg
     * @return
     */
    @RequestMapping("/getUrl")
    public String getUrl(String FileName){
            String url = QingStorUtil.getUrl(FileName);
            return url;
    }




}
